package com.booksystem.utils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Random;
import org.springframework.stereotype.Component;

/**
 * <p>
 *   订单号生成器工具类
 * </p>
 * @author 段伟豪
 */
@Component
public class OrderNoGenerator {

    private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");

    /**
     * 生成订单编号
     *
     * @return 订单编号字符串
     */
    public String generateOrderNo() {
        LocalDateTime now = LocalDateTime.now();
        String timestampPart = now.format(DATE_FORMATTER);
        Random random = new Random();
        StringBuilder sb = new StringBuilder(timestampPart);
        for (int i = 0; i < 6; i++) {
            sb.append(random.nextInt(10));
        }
        return sb.toString();
    }
}